#include "machine/ych_state.h"

int main(int argc, char *argv[]) {
    getSystemProcessor();
    char buffer[256];
    YState y_state;
    initYState(&y_state, mode = argc);
    switch (y_state.mode) {
        case YSTATE_INTERACTIVE:
            startYState(&y_state);
            while (True) {
                printf(">>>");
                fgets(buffer, sizeof(buffer), stdin);
                if (strcmp(buffer, "exit()\n") == 0) {
                    break;
                } else if (strcmp(buffer, "\n") != 0) {
                    readLine(&y_state.reader, buffer);
                } else {
                    if (!setjmp(exception_buffer1)) {
                        run1YState(&y_state, buffer);
                    } else {
                        rollbackYState(&y_state);
                        showErrors(&y_state);
                    }
                }
            }
            break;
        case YSTATE_INPUT:
            if (!setjmp(exception_buffer2))
                run2YState(&y_state, argv[1]);
            else
                showErrors(&y_state);
            break;
    }
    destroyYState(&y_state);

    return 0;
}